﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Api.Filter;
using Customer.Bussiness_Service; 
using Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ServiceCore;

namespace Customer.Areas.System.Controllers
{
    [ApiController, Area("System"), Route("/[area]/Role/[action]"), Customer_Admin]
    public class menuController : ControllerBase
    {
        private readonly Imenu_service _service;
        private readonly IToole_DI _tool;
        public menuController(Imenu_service service, IToole_DI tool)
        {
            _service = service;
            _tool = tool;
        }

        #region 菜单信息
        /// <summary>
        /// 获取菜单列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultListModel<rk_menulist> GetMenuList(Base_List_Params query)
        {
            var result = _service.get_pagelist(query);
            return result;
        }
        /// <summary>
        /// 保存菜单信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultModel SaveMenu(rk_menu query)
        {
            _tool.di_es.Add_Log("=====保存菜单信息_请求====" + Newtonsoft.Json.JsonConvert.SerializeObject(query), "/API_Menu");
            var result = _service.save(query);
            _tool.di_es.Add_Log("=====保存菜单信息_结果====" + Newtonsoft.Json.JsonConvert.SerializeObject(result), "/API_Menu");
            return result;
        }
        /// <summary>
        /// 根据ID获取单条菜单信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel GetMenuModel(string mid)
        {
            var result = _service.get_model(mid);
            return result;
        }
        /// <summary>
        /// 删除菜单信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel DelMenu(string mid)
        {
            _tool.di_es.Add_Log("=====删除菜单信息_请求====" + mid, "/API_Menu");
            var result = _service.del_item(mid);
            _tool.di_es.Add_Log("=====删除菜单信息_结果====" + Newtonsoft.Json.JsonConvert.SerializeObject(result), "/API_Menu");
            return result;
        }
        /// <summary>
        /// 获取我的菜单权限
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel GetMyMenu(menu_type menu_type = menu_type.AdminWeb)
        {
            var result = _service.get_my_list(menu_type);
            return result;
        }
        /// <summary>
        /// 获取指定角色权限列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel GetRoleMenu(string role_id, menu_type menu_type = menu_type.AdminWeb)
        {
            var result = _service.get_role_list(role_id, menu_type);
            return result;
        }

        /// <summary>
        /// 获取所有菜单权限的列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel GetALLTreeMenu(menu_type menu_type = menu_type.AdminWeb)
        {
            var result = _service.get_all_list(menu_type);
            return result;
        }
        #endregion 
    }
}